<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/21
 * Time: 10:05
 */
namespace  Admin\Controller;
use Admin\Model\BaseinfoVersionModel;
use Admin\Model\InspectioninfoModel;
use Base\Controller\CurdController;
class  DefaultInspectioninfoController extends CurdController{
    public function __construct()
    {
        parent::__construct();
    }
    /**
     * 获取所有数据并注入模板
     * */
    protected function getAll()
    {
        if($_REQUEST['selected']){
            $limit=$_REQUEST['selected'];
        }else{
            $limit=20;
        }
        if(!I('get.del')){
            $where['status']=1;
        }else{
            $where['status']=0;
        }
        if($_REQUEST['hid']){
               $where['hospital_id']= $_REQUEST['hid'];
        }
        $data = $this->model->pageToView($limit, true,$where);
//        dump($data);
        $this->assign("page", $data['page']);
        $this->assign("list", $data['list']);
    }
    /**
     * @return mixed
     */
    public function getdefaultlist(){
        $where['hospitalid']=$_REQUEST['hospital_id'];
        $where['status']=1;
        $InspectioninfoModel=new InspectioninfoModel();
       $list=$InspectioninfoModel->where($where)->select();
       $this->ajaxReturn($list);
    }
    protected function addAfter($data)
    {
        $BaseinfoVersionModel=new BaseinfoVersionModel();
        $controller = hump2underline(CONTROLLER_NAME);
        $infos=$BaseinfoVersionModel->where(array('name'=>$controller))->find();
        $data['version']=$infos['version'];
        $ids=$this->model->order('id desc')->find();
        $data['id']=$ids['id']+1;
        return $data;
    }
    protected function editAfter($data)
    {
        $BaseinfoVersionModel=new BaseinfoVersionModel();
        $controller = hump2underline(CONTROLLER_NAME);
        $infos=$BaseinfoVersionModel->where(array('name'=>$controller))->find();
        $data['version']=$infos['version'];
        return $data;
    }

}